package dingding.代理模式.jdk动态代理;

import java.lang.reflect.Proxy;

public class ProxyFactory {

    public static Object getProxy(Object target) {
        return Proxy.newProxyInstance(
                target.getClass().getClassLoader(), // 目标类的类加载
                target.getClass().getInterfaces(),  // 代理需要实现的接口，可指定多个
                new MyProxy(target)   // 代理对象对应的自定义 InvocationHandler
        );
    }

    public static void main(String[] args) {
        MailService smsService = (MailService) ProxyFactory.getProxy(new MailServiceImpl());
        smsService.send("发送你吗呢");
    }
}
